package com.study.Thread;

/**
 * 通过实现Runnable方法调用多线程
 */
public class ImpRunnable {
    public static void main(String[] args) {
        new Thread(new MyThread()).start();
        new Thread(new MyThread()).start();
    }
}
class MyThread implements Runnable{
static int tickets=1000;
boolean flag=true;
    public void run() {
        while (flag){
            synchronized ("abd"){
                if (tickets<=0){
                    flag=false;
                    return;
                }else {
                    tickets--;
                    System.out.println(Thread.currentThread().getName()+"已售出一张，剩余："+tickets);
                }
            }
        }
    }
}
